package com.baymax.test.scene.demo

import android.animation.ValueAnimator
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
import androidx.lifecycle.Lifecycle
import com.baymax.test.scene.BaseScene
import com.baymax.test.scene.addButton
import com.baymax.test.scene.addDFView
import com.baymax.test.scene.newSceneFlexContainer

class LayoutScene : BaseScene() {
    override fun onCreateView(p0: LayoutInflater, p1: ViewGroup, p2: Bundle?): View {
        return p1.newSceneFlexContainer {
            setPaddingRelative(0, 300, 0, 300)
            val ctx = p1.context
            val animate = addDFView(100, 100, View(ctx)) {
                setBackgroundColor(Color.RED)
            }

            addButton("start translate Y") {
                animate.animate().translationY(100f).setDuration(300).start()
            }

            addButton("reset translate Y") {
                animate.animate().translationY(0f).setDuration(300).start()
            }

            addButton("set mt -200") {
                (animate.layoutParams as MarginLayoutParams).topMargin = -200
                requestLayout()
            }
            addButton("set mt 200") {
                (animate.layoutParams as MarginLayoutParams).topMargin = 200
                requestLayout()
            }

            addButton("set mt 0") {
                (animate.layoutParams as MarginLayoutParams).topMargin = 0
                requestLayout()
            }

        }
    }

}